package com.xyy.saas.payment.constants;

import com.xyy.saas.payment.adapter.channel.fm.config.BankConfigManager;
import com.xyy.saas.payment.common.constants.ChannelProductConstants;
import com.xyy.saas.payment.cores.enums.FBankPowerIdEnum;
import com.xyy.saas.payment.cores.enums.PayModeEnum;
import com.xyy.saas.payment.cores.enums.TransactionStatusEnum;
import com.xyy.saas.payment.cores.enums.TransactionTypeEnum;
import com.xyy.saas.payment.enums.BusinessType;
import com.xyy.saas.payment.enums.CostType;
import com.xyy.saas.payment.manage.cores.bo.SyncFMPayReportConfigBO;
import com.xyy.saas.payment.manage.cores.enums.BusinessIdTypeEnum;
import com.xyy.saas.payment.manage.cores.enums.ChannelEnum;
import com.xyy.saas.payment.pojo.bo.PlatformAccountBo;
import com.xyy.saas.payment.pojo.vo.DictEntity;
import com.xyy.saas.payment.service.PlatformAccountsManage;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class DictMapBean {

    @Autowired
    private BankConfigManager bankConfigManager;
    @Autowired
    private PlatformAccountsManage platformAccountsManage;

    @Bean
    public List<DictEntity> fuminBusinessTypeMap(){
        List<DictEntity> list = new ArrayList<>();
        for (BusinessType businessType : BusinessType.values()) {
            if(businessType.isIgnore()) {
                continue;
            }

            DictEntity dict = new DictEntity();
            dict.setKey(businessType.getCode());
            dict.setLabel(businessType.getDesc());
            dict.setValue(businessType.getCode());
            list.add(dict);
        }
        List<SyncFMPayReportConfigBO> fuminAccountConfig = bankConfigManager.getFuminAccountConfig();
        for (SyncFMPayReportConfigBO bo : fuminAccountConfig) {
            for (DictEntity dictEntity : list) {
                if(dictEntity.getValue().equals(bo.getBusinessType())) {
                    DictEntity dict = new DictEntity();
                    dict.setKey(bo.getAccountType());
                    dict.setLabel(bo.getDesc());
                    dict.setValue(bo.getAccountType());
                    if(CollectionUtils.isEmpty(dictEntity.getChildrenList())) {
                        List<DictEntity> tmp = new ArrayList<>();
                        tmp.add(dict);
                        dictEntity.setChildrenList(tmp);
                    }else {
                        dictEntity.getChildrenList().add(dict);
                    }
                }
            }
        }
        return list;
    }

    @Bean
    public List<DictEntity> fuminWithdrawBusinessTypeMap(){
        List<DictEntity> list = new ArrayList<>();
        for (BusinessType businessType : BusinessType.values()) {
            if(businessType.isIgnore()) {
                continue;
            }

            DictEntity dict = new DictEntity();
            dict.setKey(businessType.getCode());
            dict.setLabel(businessType.getDesc());
            dict.setValue(businessType.getCode());
            list.add(dict);
        }
        List<PlatformAccountBo> platformAccount = platformAccountsManage.getPlatformAccount();
        for (PlatformAccountBo bo : platformAccount) {
            for (DictEntity dictEntity : list) {
                if(dictEntity.getValue().equals(bo.getBusinessType())) {
                    DictEntity dict = new DictEntity();
                    dict.setKey(bo.getAccountType());
                    dict.setLabel(bo.getAccountName());
                    dict.setValue(bo.getAccountType());
                    if(CollectionUtils.isEmpty(dictEntity.getChildrenList())) {
                        List<DictEntity> tmp = new ArrayList<>();
                        tmp.add(dict);
                        dictEntity.setChildrenList(tmp);
                    }else {
                        dictEntity.getChildrenList().add(dict);
                    }
                }
            }
        }
        return list;
    }

    @Bean
    public Map<String, String> businessIdTypeMap(){
        Map<String, String> map = new HashMap<>();
        for (BusinessIdTypeEnum businessIdType: BusinessIdTypeEnum.values()) {
            map.put(businessIdType.getType(), businessIdType.getDesc());
        }
        return map;
    }

    @Bean
    public Map<String, String> fuminCostTypeMap(){
        Map<String, String> map = new HashMap<>();
        for (CostType  costType: CostType.values()) {
            map.put(costType.getCode(), costType.getDesc());
        }
        return map;
    }

    @Bean
    public Map<String, String> channelProductTypeMap(){
        Map<String, String> map = new HashMap<>();
        map.put(ChannelProductConstants.QIFUTONG, "企富通");
        return map;
    }

    @Bean
    public Map<String, String> fbankPowerIdTypeMap(){
        Map<String, String> map = new HashMap<>();
        for(FBankPowerIdEnum powerIdEnum : FBankPowerIdEnum.values()) {
            map.put(powerIdEnum.getPowerId(), String.valueOf(powerIdEnum));
        }
        return map;
    }

    @Bean
    public Map<String, String> payAmountReportBusinessType(){
        Map<String, String> map = new HashMap<>();
        return map;
    }

    @Bean
    public Map<String, String> payAmountReportChannelType(){
        Map<String, String> map = new HashMap<>();
        return map;
    }

    @Bean
    public Map<String, String> payAmountReportBusinessOrderType(){
        Map<String, String> map = new HashMap<>();
        return map;
    }

    // ====== 开户相关
    @Bean
    public Map<String, String> openAccountContactTypeMap(){
        Map<String, String> map = new HashMap<>();
        map.put("1","其他联系人1");
        map.put("2","其他联系人2");
        map.put("3","其他联系人3");
        map.put("4","法人");
        map.put("5","财务人员");
        return map;
    }
    @Bean
    public Map<String, String> openAccountCertTypeMap(){
        Map<String, String> map = new HashMap<>();
        map.put("1","身份证");
        map.put("2","营业执照");
        map.put("3","统一信用代码");
        return map;
    }

    // =========== 交易相关

    // 支付渠道
    @Bean
    public Map<String, String> payChannelTypeMap(){
        Map<String, String> map = new HashMap<>();
        for(ChannelEnum channelEnum : ChannelEnum.values()) {
            map.put(channelEnum.getCode(), channelEnum.getName());
        }
        return map;
    }

    // 支付方式
    @Bean
    public Map<String, String> payModeTypeMap(){
        Map<String, String> map = new HashMap<>();
        for(PayModeEnum payModeEnum : PayModeEnum.values()) {
            map.put(payModeEnum.getMode(), String.valueOf(payModeEnum));
        }
        return map;
    }

    // 交易类型
    @Bean
    public Map<String, String> transactionTypeMap(){
        Map<String, String> map = new HashMap<>();
        for(TransactionTypeEnum transactionTypeEnum : TransactionTypeEnum.values()) {
            map.put(transactionTypeEnum.getCode(), transactionTypeEnum.getDesc());
        }
        return map;
    }
    // 交易状态
    @Bean
    public Map<String, String> transactionStatusTypeMap(){
        Map<String, String> map = new HashMap<>();
        for(TransactionStatusEnum transactionStatusEnum : TransactionStatusEnum.values()) {
            map.put(transactionStatusEnum.getCode(), transactionStatusEnum.getDesc());
        }
        return map;
    }




}
